﻿using System;
using System.IO.Ports;
using System.Windows.Forms;

namespace LDSProject.Forms
{
    public partial class PortConfigForm : Form
    {
        public PortConfigForm()
        {
            InitializeComponent();
        }

        private void PortConfigForm_Load(object sender, EventArgs e)
        {
            cbPortName.DataSource = SerialPort.GetPortNames();
            var portName = Properties.Settings.Default.PortName;

            if (cbPortName.Items.Contains(portName))
            {
                cbPortName.SelectedItem = portName;
            }
            else if (cbPortName.Items.Count > 0)
            {
                cbPortName.SelectedIndex = 0;
            }
        }

        private void cbPortName_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (cbPortName.SelectedItem != null)
            {
                Properties.Settings.Default.PortName = cbPortName.SelectedItem.ToString();
                Properties.Settings.Default.Save();
            }

            DialogResult = DialogResult.OK;
        }
    }
}
